# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
summary(fit)
# example 2.1:logistic regression with fiml estimation
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","atriskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","read9grp","stanread7",
"math1","math2","math3","math9","math9grp","stanmath7")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9grp","read1","lrnprob1","behsymp1")])
# set ranges (nodes) for pseudo-imputations
nodes.hispanic <- c(0,1)
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9grp <- c(0,1)
nodes.read1 <- seq(30, 160, by = 2)
nodes.lrnprob1 <- seq(20, 100, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1 ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1 ~ lrnprob1 + behsymp1, nodes = nodes.read1)
# model for read9grp outcome: f(read9grp|read1,lrnprob1,behsymp1)
model.read9grp <- list( "model" = "logistic", "formula" = read9grp ~ read1 + lrnprob1 + behsymp1, nodes = nodes.read9grp)
# model for hispanic auxiliary variable f(read2|read9grp,read1,lrnprob1,behsymp1)
model.hispanic <- list("model" = "logistic", "formula" = hispanic ~ read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.hispanic)
# model for read2 auxiliary variable f(read2|read9grp,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ hispanic + read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9grp,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + hispanic + read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(read2 = model.read2, hispanic = model.hispanic, read9grp = model.read9grp, behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
summary(fit)
# example 2.1:logistic regression with fiml estimation
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","read9grp","stanread7",
"math1","math2","math3","math9","math9grp","stanmath7")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9grp","read1","lrnprob1","behsymp1")])
# set ranges (nodes) for pseudo-imputations
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9grp <- c(0,1)
nodes.read1 <- seq(30, 160, by = 2)
nodes.lrnprob1 <- seq(20, 100, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1 ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1 ~ lrnprob1 + behsymp1, nodes = nodes.read1)
# model for read9grp outcome: f(read9grp|read1,lrnprob1,behsymp1)
model.read9grp <- list( "model" = "logistic", "formula" = read9grp ~ read1 + lrnprob1 + behsymp1, nodes = nodes.read9grp)
# model for read2 auxiliary variable f(read2|read9grp,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9grp,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(read2 = model.read2, read9grp = model.read9grp, behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
summary(fit)
# example 2.1:logistic regression with fiml estimation
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","read9grp","stanread7",
"math1","math2","math3","math9","math9grp","stanmath7")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9grp","read1","lrnprob1","behsymp1")])
# set ranges (nodes) for pseudo-imputations
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9grp <- c(0,1)
nodes.read1 <- seq(30, 160, by = 2)
nodes.lrnprob1 <- seq(20, 100, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1 ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1 ~ lrnprob1 + behsymp1, nodes = nodes.read1)
# model for read9grp outcome: f(read9grp|read1,lrnprob1,behsymp1)
model.read9grp <- list( "model" = "logistic", "formula" = read9grp ~ read1 + lrnprob1 + behsymp1, nodes = nodes.read9grp)
# model for read2 auxiliary variable f(read2|read9grp,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9grp,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + read9grp + read1 + lrnprob1 + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1, read9grp = model.read9grp, read2 = model.read2)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
summary(fit)
# example 2.1:logistic regression with fiml estimation
library(fdir)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","read9grp","stanread7",
"math1","math2","math3","math9","math9grp","stanmath7")
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read1","lrnprob1","behsymp1")])
# example x: moderated regression with fiml estimation and auxiliary variables
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; hispanic ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; behsymp1 ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
# example x: moderated regression with fiml estimation and auxiliary variables
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; hispanic ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; behsymp1 ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
descriptives
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","hispanic","read9","read1.cgm","lrnprob1.cgm","behsymp1")])
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","behsymp1")])
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9 <- seq(30, 130, by = 2)
nodes.read1 <- seq(-55, 75, by = 2)
nodes.lrnprob1 <- seq(-30, 50, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# example x: moderated regression with fiml estimation and auxiliary variables
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; hispanic ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; behsymp1 ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","behsymp1")])
# set ranges (nodes) for pseudo-imputations
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9 <- seq(30, 130, by = 2)
nodes.read1 <- seq(-55, 75, by = 2)
nodes.lrnprob1 <- seq(-30, 50, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1.cgm ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1.cgm ~ lrnprob1.cgm + behsymp1, nodes = nodes.read1)
# model for read9 outcome: f(read9|read1,lrnprob1,behsymp1)
model.read9 <- list( "model" = "linreg", "formula" = read9 ~ read1.cgm + lrnprob1.cgm + read1.cgm*lrnprob1.cgm + behsymp1, nodes = nodes.read9)
# model for hispanic auxiliary variable f(hispanic|read9,read1,lrnprob1,behsymp1)
model.hispanic <- list("model" = "logistic", "formula" = hispanic ~ read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.hispanic)
# model for read2 auxiliary variable f(read2|hispanic,read9,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ hispanic + read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + hispanic + read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1, read9 = model.read9, read2 = model.read2)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
# example x: moderated regression with fiml estimation and auxiliary variables
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("behaviorachievement.dat", na.strings = "999")
names(data) <- c("id","male","hispanic","riskgrp","atrisk","behsymp1","lrnprob1",
"read1","read2","read3","read9","readgrp9","stanread7",
"math1","math2","math3","math9","mathgrp9","stanmath7")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread7 ~ 1; read2 ~ 1; hispanic ~ 1; read9 ~ 1; read1 ~ 1; lrnprob1 ~ 1; behsymp1 ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variables
data$read1.cgm <- data$read1 - descriptives$mean["read1"]
data$lrnprob1.cgm <- data$lrnprob1 - descriptives$mean["lrnprob1"]
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread7","read2","read9","read1.cgm","lrnprob1.cgm","behsymp1")])
# set ranges (nodes) for pseudo-imputations
nodes.stanread7 <- seq(80, 420, by = 5)
nodes.read2 <- seq(10, 160, by = 2)
nodes.read9 <- seq(30, 130, by = 2)
nodes.read1 <- seq(-55, 75, by = 2)
nodes.lrnprob1 <- seq(-30, 50, by = 2)
nodes.behsymp1 <- seq(10, 100, by = 2)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1.cgm ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1.cgm ~ lrnprob1.cgm + behsymp1, nodes = nodes.read1)
# model for read9 outcome: f(read9|read1,lrnprob1,behsymp1)
model.read9 <- list( "model" = "linreg", "formula" = read9 ~ read1.cgm + lrnprob1.cgm + read1.cgm*lrnprob1.cgm + behsymp1, nodes = nodes.read9)
# model for hispanic auxiliary variable f(hispanic|read9,read1,lrnprob1,behsymp1)
model.hispanic <- list("model" = "logistic", "formula" = hispanic ~ read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.hispanic)
# model for read2 auxiliary variable f(read2|hispanic,read9,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ hispanic + read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + hispanic + read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1, read9 = model.read9, read2 = model.read2)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.read9, ind = predictor.models)
summary(fit)
# model for behsymp1 predictor: f(behsymp1)
model.behsymp1 <- list( "model" = "linreg", "formula" = behsymp1 ~ 1, nodes = nodes.behsymp1)
# model for lrnprob1 predictor: f(lrnprob1|behsymp1)
model.lrnprob1 <- list( "model" = "linreg", "formula" = lrnprob1.cgm ~ behsymp1, nodes = nodes.lrnprob1)
# model for read1 predictor: f(read1|lrnprob1,behsymp1)
model.read1 <- list( "model" = "linreg", "formula" = read1.cgm ~ lrnprob1.cgm + behsymp1, nodes = nodes.read1)
# model for read9 outcome: f(read9|read1,lrnprob1,behsymp1)
model.read9 <- list( "model" = "linreg", "formula" = read9 ~ read1.cgm + lrnprob1.cgm + read1.cgm*lrnprob1.cgm + behsymp1, nodes = nodes.read9)
# model for read2 auxiliary variable f(read2|hispanic,read9,read1,lrnprob1,behsymp1)
model.read2 <- list("model" = "linreg", "formula" = read2 ~ read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.read2)
# model for stanread7 auxiliary variable f(stanread7|read2,read9,read1,lrnprob1,behsymp1)
model.stanread7 <- list("model" = "linreg", "formula" = stanread7 ~ read2 + read9 + read1.cgm + lrnprob1.cgm + behsymp1, nodes = nodes.stanread7)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1, read9 = model.read9, read2 = model.read2)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.read9, ind = predictor.models)
# combine predictor models into a list
predictor.models <- list(behsymp1 = model.behsymp1, lrnprob1 = model.lrnprob1, read1 = model.read1, read9 = model.read9, read2 = model.read2)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread7, ind = predictor.models)
summary(fit)
# example 5.1: curvilinear regression with fiml estimation
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread ~ 1; atrisk ~ 1; mathpost ~ 1; anxiety ~ 1; frlunch ~ 1; efficacy ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variable
data$anxiety.cgm <- data$anxiety - descriptives$mean["anxiety"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy")])
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ mathpre, nodes = nodes.frlunch)
# example 5.1: curvilinear regression with fiml estimation
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread ~ 1; atrisk ~ 1; mathpost ~ 1; anxiety ~ 1; frlunch ~ 1; efficacy ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variable
data$anxiety.cgm <- data$anxiety - descriptives$mean["anxiety"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = .20)
nodes.anxiety <- seq(-30, 30, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "oprobit", "formula" = efficacy ~ frlunch + mathpre, nodes = nodes.efficacy)
# model for anxiety predictor: f(anxiety|efficacy,frlunch,condition,mathpre)
model.anxiety <- list("model"="linreg", "formula" = anxiety.cgm ~ efficacy + frlunch + mathpre, nodes = nodes.anxiety)
# model for mathpost outcome: f(mathpost|anxiety,efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ anxiety.cgm + I(anxiety.cgm^2) + efficacy + frlunch + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, anxiety = model.anxiety, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 5.1: curvilinear regression with fiml estimation
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread ~ 1; atrisk ~ 1; mathpost ~ 1; anxiety ~ 1; frlunch ~ 1; efficacy ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variable
data$anxiety.cgm <- data$anxiety - descriptives$mean["anxiety"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = .20)
nodes.anxiety <- seq(-30, 30, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + mathpre, nodes = nodes.efficacy)
# model for anxiety predictor: f(anxiety|efficacy,frlunch,condition,mathpre)
model.anxiety <- list("model"="linreg", "formula" = anxiety.cgm ~ efficacy + frlunch + mathpre, nodes = nodes.anxiety)
# model for mathpost outcome: f(mathpost|anxiety,efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ anxiety.cgm + I(anxiety.cgm^2) + efficacy + frlunch + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.stanread)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, anxiety = model.anxiety, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
# example 5.1: curvilinear regression with fiml estimation
library(fdir)
library(lavaan)
library(mdmb)
##################################################
# read data
##################################################
# set working directory
set()
# read raw data from working directory
data <- read.table("mathachievement.dat", na.strings = "999")
names(data) <- c("id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# estimate means and center variables
##################################################
# estimate sample statistics in lavaan
model <- "stanread ~ 1; atrisk ~ 1; mathpost ~ 1; anxiety ~ 1; frlunch ~ 1; efficacy ~ 1; mathpre ~ 1;"
descriptives <- inspectSampleCov(model, data, missing = "fiml")
# center lower-order variable
data$anxiety.cgm <- data$anxiety - descriptives$mean["anxiety"]
##################################################
# analysis
##################################################
# summarize incomplete predictors to determine ranges for pseudo-imputations
summary(data[,c("stanread","mathpost","anxiety.cgm","efficacy")])
# set ranges (nodes) for pseudo-imputations
nodes.frlunch <- c(0,1)
nodes.efficacy <- seq(1, 6, by = .20)
nodes.anxiety <- seq(-30, 30, by = 2)
nodes.mathpost <- seq(30, 90, by = 2)
nodes.atrisk <- c(0,1)
nodes.stanread <- c(20, 80, by = 2)
# model for frlunch predictor: f(frlunch|condition,mathpre)
model.frlunch <- list("model" = "logistic", "formula" = frlunch ~ mathpre, nodes = nodes.frlunch)
# model for efficacy predictor: f(efficacy|frlunch,condition,mathpre)
model.efficacy <- list("model" = "linreg", "formula" = efficacy ~ frlunch + mathpre, nodes = nodes.efficacy)
# model for anxiety predictor: f(anxiety|efficacy,frlunch,condition,mathpre)
model.anxiety <- list("model"="linreg", "formula" = anxiety.cgm ~ efficacy + frlunch + mathpre, nodes = nodes.anxiety)
# model for mathpost outcome: f(mathpost|anxiety,efficacy,frlunch,condition,mathpre)
model.mathpost <- list("model" = "linreg", "formula" = mathpost ~ anxiety.cgm + I(anxiety.cgm^2) + efficacy + frlunch + mathpre, nodes = nodes.mathpost)
# model for atrisk auxiliary variable: f(atrisk|mathpost,efficacy,frlunch,condition,mathpre)
model.atrisk <- list("model" = "logistic", "formula" = atrisk ~ mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.atrisk)
# model for stanread auxiliary variable: f(stanread|atrisk,mathpost,efficacy,frlunch,condition,mathpre)
model.stanread <- list("model" = "linreg", "formula" = stanread ~ atrisk + mathpost + anxiety.cgm + efficacy + frlunch + mathpre, nodes = nodes.stanread)
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, anxiety = model.anxiety)
fit <- frm_em(dat = data, dep = mathpost = model.mathpost, ind = predictor.models)
fit <- frm_em(dat = data, dep = model.mathpost, ind = predictor.models)
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, anxiety = model.anxiety, mathpost = model.mathpost)
fit <- frm_em(dat = data, dep = model.atrisk, ind = predictor.models)
# combine predictor models into a list
predictor.models <- list(frlunch = model.frlunch, efficacy = model.efficacy, anxiety = model.anxiety, mathpost = model.mathpost, atrisk = model.atrisk)
# estimate factored regression model w mdmb
fit <- frm_em(dat = data, dep = model.stanread, ind = predictor.models)
